﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Jungle.Code.DAL;
using Jungle.Code.Utils;
using System.Data.SqlClient;
using System.Data;

namespace Jungle.Code.BookManager
{
    public class CategoryType
    {
        public string err = "";
        public List<CategoryType> CategoriesList;

        private static string ConnectionString = DBHelper.ConnectionString;

        #region Fields

        private int id;
        private string title;

        #endregion

        #region Properties

        public int ID { get { return id; } set { id = value; } }
        public string Title { get { return title; } set { title = value; } }

        #endregion

        //-----------------------------------------------------------------
        public int GetAllGategories()
        {
            int count = 0;
            try
            {
                
                using (SqlConnection connect = new SqlConnection(ConnectionString))
                {
                    CategoriesList = new List<CategoryType>();
                    SqlCommand command = new SqlCommand("catalog.BookCategory_GetAll", connect);
                    SqlDataReader reader = null;

                    command.CommandType = CommandType.StoredProcedure;
                    command.Connection.Open();
                    reader = command.ExecuteReader();

                    if (reader == null) { return 0; }

                    while (reader.Read())
                    {
                        CategoryType c = new CategoryType();
                        c.ID = (int)reader["CategoryId"];
                        c.Title = reader["Title"].ToString().Trim();
                        CategoriesList.Add(c);
                        count++;
                    }

                    reader.Close();

                    command.Connection.Close();


                }
                return count;
            }
            catch
            {
                return 0;
            }
        }
        //-----------------------------------------------------------------
        public void Add()
        { }
        //-----------------------------------------------------------------
        public void Delete()
        { }
        //-----------------------------------------------------------------
        public void Update()
        { }

    }
}
